package org.jvnet.hudson.client_demo;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;
import java.util.Set;

import org.tmatesoft.svn.core.SVNException;
import org.tmatesoft.svn.core.SVNLogEntry;
import org.tmatesoft.svn.core.SVNLogEntryPath;
import org.tmatesoft.svn.core.SVNURL;
import org.tmatesoft.svn.core.auth.ISVNAuthenticationManager;
import org.tmatesoft.svn.core.io.SVNRepository;
import org.tmatesoft.svn.core.io.SVNRepositoryFactory;
import org.tmatesoft.svn.core.wc.SVNWCUtil;
import org.tmatesoft.svn.core.wc2.SvnLog;
import org.tmatesoft.svn.core.wc2.SvnOperationFactory;

public class ChkSVNfileLog {

	public static void main(String[] args) throws SVNException {

		final String url ="https://10.144.136.56/svndps_test/dpssvn01/MOrderWAR/Bginfo.exe";
		final String usr ="dpssvn01";
		final String pwd ="abcd1234";
		
		
		final SVNRepository repo = SVNRepositoryFactory.create(SVNURL.parseURIEncoded(url));
		final ISVNAuthenticationManager authManager = SVNWCUtil.createDefaultAuthenticationManager(usr,pwd);
		repo.setAuthenticationManager(authManager);
		

		final SvnOperationFactory svnOperationFactory = new SvnOperationFactory();
		final SvnLog log = svnOperationFactory.createLog();
		Set changedPathsSet = null;
		Collection logEntries = repo.log( new String[] { "" } ,null , (long)1 , (long) -1 , true , true );
		ArrayList<Long> verSet = new ArrayList<Long>();
        for ( Iterator entries = logEntries.iterator( ); entries.hasNext( ); ) {
            SVNLogEntry logEntry = ( SVNLogEntry ) entries.next( );
            if ( logEntry.getChangedPaths( ).size( ) > 0 ) {
            	changedPathsSet = logEntry.getChangedPaths( ).keySet( );
                for ( Iterator changedPaths = changedPathsSet.iterator( ); changedPaths.hasNext( ); ) {
                    SVNLogEntryPath entryPath = ( SVNLogEntryPath ) logEntry.getChangedPaths( ).get( changedPaths.next( ) );
                    if ( (entryPath.getType()=='A' || entryPath.getType()=='M') && entryPath.getPath( ).indexOf("/"+"")!=-1) {
                    	verSet.add( logEntry.getRevision());
                    }
                }
            }
        }
        Collections.reverse(verSet);
        
        for(int i=0;i<verSet.size();i++ ) {
        	System.out.println(verSet.get(i));
        }

	}

}
